import * as $Dysmsapi20170525 from "@alicloud/dysmsapi20170525";
import * as $OpenApi from "@alicloud/openapi-client";
import * as $Util from "@alicloud/tea-util";
import { aliAccessKeyId, aliAccessKeySecret } from "@/configs/ali";

const client = await createClient();
async function createClient() {
	const config = new $OpenApi.Config({
		accessKeyId: aliAccessKeyId,
		accessKeySecret: aliAccessKeySecret,
	});
	config.endpoint = "dysmsapi.aliyuncs.com";
	const Dysmsapi20170525 = (await import("@alicloud/dysmsapi20170525")).default;
	return new Dysmsapi20170525(config);
}
export const sendSmsRequest = async (option: { signName: string; templateCode: string; phoneNumbers: string; templateParam: string }) => {
	const request = new $Dysmsapi20170525.SendSmsRequest(option);
	try {
		await client.sendSmsWithOptions(request, new $Util.RuntimeOptions({}));
	} catch (err: any) {
		console.log(err.message);
		console.log(err.data["Recommend"]);
	}
};
